﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SmartMathLibrary.Statistics
{
    /// <summary>
    /// This class represents a timeseries.
    /// </summary>
    [Serializable]
    public class TimeSeries : ITimeSeries
    {
        /// <summary>
        /// The data of the timeseries.
        /// </summary>
        private GeneralVector data;

        /// <summary>
        /// Initializes a new instance of the <see cref="TimeSeries"/> class.
        /// </summary>
        /// <param name="data">The data of the timeseries.</param>
        public TimeSeries(GeneralVector data)
        {
            if (data == (GeneralVector) null)
            {
                throw new ArgumentNullException("data");
            }

            this.data = data;
        }

        /// <summary>
        /// Gets or sets the data of the timeseries.
        /// </summary>
        /// <value>The data of the timeseries.</value>
        public GeneralVector Data
        {
            get { return this.data; }
            set { this.data = value; }
        }

        /// <summary>
        /// Gets or sets the <see cref="System.Double"/> at the specified index.
        /// </summary>
        /// <value>The value of the timeseries at the specified position.</value>
        public double this[int index]
        {
            get { return this.data[index]; }
            set { this.data[index] = value; }
        }

        /// <summary>
        /// Generates the index vector of the timeseries.
        /// </summary>
        /// <returns>The index vector of the timeseries</returns>
        public GeneralVector GenerateIndexVector()
        {
            GeneralVector result = new GeneralVector(this.data.Count);

            for (int i = 0; i < result.Count; i++)
            {
                result[i] = i;
            }

            return result;
        }

        /// <summary>
        /// Implements the operator ==.
        /// </summary>
        /// <param name="a">The first timeseries instance.</param>
        /// <param name="b">The second timeseries instance.</param>
        /// <returns>The result of the operator.</returns>
        public static bool operator ==(TimeSeries a, TimeSeries b)
        {
            if (System.Object.ReferenceEquals(a, b))
            {
                return true;
            }

            if (((object) a == null) || ((object) b == null))
            {
                return false;
            }

            return (a.Data == b.Data);
        }

        /// <summary>
        /// Implements the operator !=.
        /// </summary>
        /// <param name="a">The first timeseries instance.</param>
        /// <param name="b">The second timeseries instance.</param>
        /// <returns>The result of the operator.</returns>
        public static bool operator !=(TimeSeries a, TimeSeries b)
        {
            return !(a == b);
        }

        /// <summary>
        /// Determines whether the specified <see cref="System.Object"/> is equal to this instance.
        /// </summary>
        /// <param name="obj">The <see cref="System.Object"/> to compare with this instance.</param>
        /// <returns>
        /// 	<c>true</c> if the specified <see cref="System.Object"/> is equal to this instance; otherwise, <c>false</c>.
        /// </returns>
        /// <exception cref="T:System.NullReferenceException">The <paramref name="obj"/> parameter is null.</exception>
        public override bool Equals(object obj)
        {
            return base.Equals(obj);
        }

        /// <summary>
        /// Returns a hash code for this instance.
        /// </summary>
        /// <returns>
        /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. 
        /// </returns>
        public override int GetHashCode()
        {
            return base.GetHashCode();
        }

        /// <summary>
        /// Returns a <see cref="System.String"/> that represents this instance.
        /// </summary>
        /// <returns>
        /// A <see cref="System.String"/> that represents this instance.
        /// </returns>
        public override string ToString()
        {
            String result = "";

            for (int i = 0; i < this.data.Count; i++)
            {
                result += "{" + i + ";" + this.data[i] + "}";
            }

            return result;
        }
    }
}